const path = require("path");
const colors = require("colors");
const gm = require("gm");

const FONT_CHINESE = path.resolve(
  __dirname,
  "../assets/font/ZiTiQuanXinYiJiXiangSong.ttf"
);
const FONT_ENGLISH = path.resolve(__dirname, "./assets/font/HelveticaNeue.ttc");

function massage_bg_creator(text, base_image_dir, bg_output_dir) {
  const font = FONT_CHINESE;
  return new Promise((resolve, reject) => {
    gm(base_image_dir)
      .font(font, 45)
      .fill("#fff")
      .drawText(0, 0, text, "Center")
      .write(bg_output_dir, function (err) {
        if (!err) {
          console.log(colors.green("生成文案图 => ", bg_output_dir));
          resolve(bg_output_dir);
        } else {
          reject(err);
        }
      });
  });
}

module.exports = massage_bg_creator;
